﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Xceed.Wpf.Toolkit.PropertyGrid;

namespace CPPEI.Coolzon.UI.DataPartLib.XProperty.Editors
{
    /// <summary>
    /// XSeriesLineStyleEditor.xaml 的交互逻辑
    /// </summary>
    public partial class XSeriesLineStyleEditor : UI.XProperty.XPropertyValueEditor
    {
        public static DependencyProperty PropertyValueProperty = DependencyProperty.Register("PropertyValue", typeof(SeriesLineStyle), typeof(XSeriesLineStyleEditor), new PropertyMetadata(propertyChangedCallback));
        private static void propertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            XSeriesLineStyleEditor editor = d as XSeriesLineStyleEditor;
            if (e.NewValue != null)
            {
                editor.XSeriesLineStyle = (SeriesLineStyle)e.NewValue;
            }
            else
            {
                editor.XSeriesLineStyle = null;
            }
        }
        public SeriesLineStyle XSeriesLineStyle;
        public DataPart dataPart;
        public XSeriesLineStyleEditor()
        {
            InitializeComponent();
        }

        protected override DependencyProperty GetPropertyValue()
        {
            return PropertyValueProperty;
        }

        protected override void OnXInit(PropertyItem propertyItem)
        {
            Binding binding = new Binding();
            binding.Source = propertyItem;
            binding.Path = new PropertyPath("Value");
            binding.Mode = BindingMode.TwoWay;
            this.SetBinding(PropertyValueProperty, binding);
            dataPart = propertyItem.Instance as DataPart;
        }

        protected override void OnXInit(Part partInstance, XPropertyAttribute xProperty, PropertyInfo propertyInfo, object value)
        {
            Binding binding = new Binding();
            binding.Source = partInstance;
            binding.Path = new PropertyPath(propertyInfo.Name);
            this.SetBinding(PropertyValueProperty, binding);
            dataPart = (partInstance as DataPart);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SeriesLineStyleEditWindow window = new SeriesLineStyleEditWindow(XSeriesLineStyle, dataPart.DataResult);
            if (window.ShowDialog().Value)
            {
                XSeriesLineStyle = window.RetSeriesLineStyle;
                this.UpdateXPropertyValue(window.RetSeriesLineStyle);
            }
        }
    }
}
